<#assign menu="folder">
<#assign submenu="update_folder">
<#include "/system/head.ftl">
<style type="text/css">
</style>
<!--main content start-->
<section id="main-content">
	<section class="wrapper">
		<!-- page start-->
		<div class="row">
				<div class="col-lg-9">
					<input type="hidden" class="form-control" name="folderId"
						value="<#if folder??>${folder.folderId}</#if>">
					<section class="panel">
	                  <header class="panel-heading">
	                      上传图片
	                  </header>
	                  <div class="panel-body" id="attachment">
	                  	  <ul class="grid cs-style-3">
	                      	  <#list attachmentPage.list as attachment>
	                          <li>
	                              <figure>
	                                  <img src="${basePath}/${attachment.path}" alt="img04">
	                                  <figcaption>
	                                      <a class="js_link" href="javascript:void(0);" link="${attachment.link}"  title="${attachment.name}" description="${attachment.description}"  attachmentId="${attachment.attachmentId}">修改</a>
	                                      <a class="fancybox" rel="group" href="${basePath}/${attachment.path}">查看大图</a>
	                                      <a class="js_delete" href="javascript:void(0);" name="${attachment.name}" attachmentId="${attachment.attachmentId}">删除</a>
	                                  </figcaption>
	                              </figure>
	                          </li>
	                          </#list>
	                      </ul>
	                      ${attachmentPage.pageNumHtml}
	                  </div>
	              </section>
				</div>
				<div class="col-lg-3">		
				<section class="panel">
				<div class="panel-body">
					<label for="exampleInputEmail1">所属目录</label>
						<select class="form-control" name="folderId_select" id="folderId_select">
	                   		<#list folderAll as firstFolder>
	                        	<option value="${firstFolder.folderId}"  <#if folder.folderId==firstFolder.folderId>selected</#if> <#if firstFolder.type!="photo">disabled style="background-color:#ccc;"</#if> >
	                        	├─┬─${firstFolder.name}<#if firstFolder.type!="photo">（不可选）</#if>
	                        	</option>
		                        	<#list firstFolder.folderList as secondFolder>
		                        	<option  value="${secondFolder.folderId}"  <#if folder.folderId==secondFolder.folderId>selected</#if> <#if secondFolder.type!="photo">disabled style="background-color:#ccc;"</#if>>
		                        	│&nbsp;&nbsp;&nbsp;└──${secondFolder.name}<#if secondFolder.type!="photo">（不可选）</#if>
		                        	</option>
										<#list secondFolder.folderList as thirdFolder>
			                        	<option  value="${thirdFolder.folderId}"  <#if folder.folderId==thirdFolder.folderId>selected</#if> <#if thirdFolder.type!="photo">disabled style="background-color:#ccc;"</#if>>
			                        	│&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;└──${thirdFolder.name}<#if thirdFolder.type!="photo">（不可选）</#if>
			                        	</option>
				                        	<#list thirdFolder.folderList as fourthFolder>
				                        	<option  value="${fourthFolder.folderId}"  <#if folder.folderId==fourthFolder.folderId>selected</#if> <#if fourthFolder.type!="photo">disabled style="background-color:#ccc;"</#if>>
				                        	│&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;└──${fourthFolder.name}<#if fourthFolder.type!="photo">（不可选）</#if>
				                        	</option>
				                        	</#list>
			                        	</#list>			                        	
		                        	</#list>
	                        </#list>							
	                  </select>		
	                  <label for="exampleInputEmail1">搜索目录：</label>
	                  <input type="text" class="form-control" name="stock_code" id="stock_code" value="<#if (folder??)&&(folder.name??)>${folder.name}</#if>" placeholder="股票代码">
	                  <div class="form-group">
						<button id="search_stock_btn" class="btn btn-shadow btn-primary" type="button">搜索</button>
					  </div>
					  <div class="form-group">
	                  <button id="file_upload"  class="btn btn-shadow btn-info" type="button"><i class="icon-cloud-upload"></i> 添加附件</button>
	                  </div>
				</div>
				</section>
				</div>
		</div>

		<!-- page end-->
	</section>
</section>
<!--main content end-->
<script type="text/javascript">
 	var fatherId = ${folder.fatherId};
 	var kindId = ${folder.folderId};
	var kind = "folder";	
	$(function() {
		$('#file_upload').uploadify({
			'buttonText'  		: 	'请选择文件',
	        'swf'         		: 	'${basePath}/system/assets/uploadify/uploadify.swf',
	        'uploader'    		: 	'${basePath}/admin/attachment/upload.json;jsessionid=${JSESSIONID}',
	        'formData'  		: 	{'kindId':kindId,'kind':kind},
	        'fileObjName'		: 	'file',
	        'fileTypeExts' 		: 	'*.jpg; *.png; *.gif',
	        'method'			:	'post',
	        'onQueueComplete' 	: 	function(file, data, response) {
	        	window.location.reload();
	        }
		});
		$('#folderId').change(function(){
			window.location.href = "${basePath}/admin/attachment/page.htm?folderId="+$('#folderId').val();
		});
		$('#folderId_select').change(function(){
			$('#folderId').val($("#folderId_select").val());
			kindId=$('#folderId_select').val();
			window.location.href = "${basePath}/admin/folder/photo.htm?folderId="+kindId;
			
		});
		$('#search_stock_btn').click(function(){
			var stockId=$('#stock_code').val();
			var isFind=false;
			//遍历所有的股票，选出要添加图的股票
			$("#folderId_select option").each(function (){
			    if($(this).text().indexOf(stockId)>=0){ 
				    $("#folderId_select").val();
				    kindId= $(this).val();
					window.location.href = "${basePath}/admin/folder/photo.htm?folderId="+kindId;
					isFind=true;
				}
			});
			if(!isFind)
				alert("未找到对应的股票");
		});
		
		$('#btn_reflash').click(function(){
			window.location.reload();
		});
		jQuery(".fancybox").fancybox();
		$('#attachment .js_link').click(function(){
			var attachmentId = $(this).attr("attachmentId");
			var link = $(this).attr("link");
			var title = $(this).attr("title");
			var content = $(this).attr("description");
			/*bootbox.prompt({title:"修改，当前链接为："+link, value:link,callback:function(result) {
				if (result === null) {
				}else{
					$.post("${basePath}/admin/attachment/update_link.json",{
						'attachmentId':attachmentId,'link':result},function(data){
						if(data.result){
							window.location.reload();
						}
					},"json");					
				} 
			}});*/
			bootbox.dialog({
		        message: '<style>.datepicker{z-index: 99999 !important}<\/style>'
		        	+'		                <form class="form-horizontal" role="form" id="create_report_form">'
		        	+'		                    <input type="hidden" name="attachmentId" value="'+ attachmentId +'" />'
		        	+'		                    <div class="form-group">'
		        	+'		                        <label class="col-sm-3 control-label no-padding-right" for="form_title"> 图片名称 </label>'
		        	+'		                        <div class="col-sm-9">'
		        	+'		                            <textarea class="form-control" id="title" name="title" placeholder="图片名称">'+title+'</textarea>'
		        	+'		                        </div>'
		        	+'		                    </div>'
		        	+'		                    <div class="form-group">'
		        	+'		                        <label class="col-sm-3 control-label no-padding-right">'
		        	+'		                        简介</label>'
		        	+'		                        <div class="col-sm-9">'
		        	+'		                            <textarea class="form-control" id="description" name="description" placeholder="简介">'+content+'</textarea>'
		        	+'		                        </div>'
		        	+'		                    </div>'
		        	+'		                    <div class="form-group">'
		        	+'		                        <label class="col-sm-3 control-label no-padding-right">'
		        	+'		                        链接</label>'
		        	+'		                        <div class="col-sm-9">'
		        	+'		                            <textarea class="form-control"  id="link" name="link" placeholder="链接">'+link+'</textarea>'
		        	+'		                        </div>'
		        	+'		                    </div>'
		        	+'		                  </form>',
		        title: "修改图片",
		        buttons:             
		        {
		            "success" :
		             {
		                "label" : "<i class='icon-ok'></i> 提交",
		                "className" : "btn-sm btn-success",
		                "callback": function() {
		                    var params = $("#create_report_form").serialize();
		                    $.ajax({
		                        type: "post",
		                        dataType: "json",
		                        url: "${basePath}/admin/attachment/update_link.json",
		                        data: params,
		                        jsonp: 'callback',
		                        jsonpCallback: 'callbackReportCreate',
		                        success: function(data) {
		                            /*if (data.msg == 'ok') {
		                                var reports = data.data;
		                                location.reload();
		                            }*/
		                    		window.location.reload();
		                        }
		                    });
		                }
		            }
		        }
		    });
			
			
			
		});
		$('#attachment .js_delete').click(function(){
			var file = $(this);
			bootbox.confirm("是否要删除【"+$(this).attr("name")+"】文件？", function(result) {
				if (result) {
					$.post("${basePath}/admin/attachment/delete.json",{'attachmentId':file.attr("attachmentId")},function(data){
						if(data.result){
							window.location.reload();
						}
					},"json");
				}
			});		
		});				
	});	
</script>
<#include "/system/foot.ftl">
